/* Copyright Statement:
 *
 * This software/firmware and related documentation ("MediaTek Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
 * the prior written permission of MediaTek inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of MediaTek Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * MediaTek Inc. (C) 2014. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
 * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
 * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
 *
 * The following software/firmware and/or related documentation ("MediaTek
 * Software") have been modified by MediaTek Inc. All revisions are subject to
 * any receiver's applicable license agreements with MediaTek Inc.
 */

package com.android.camera.manager;

import android.graphics.Color;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.LinearLayout;

import com.android.camera.CameraActivity;
import com.android.camera.FeatureSwitcher;
import com.android.camera.Log;
import com.android.camera.ModeChecker;
import com.android.camera.R;
import com.android.camera.manager.PickerManager.PickerListener;
import com.android.camera.ui.RGK_ControlPanelLayout;
import com.android.camera.ui.ModePickerScrollView;
import com.android.camera.ui.RGK_PageControlView;
import com.android.camera.ui.RotateImageView;
import com.android.camera.ui.RGK_ScrollControlPanelLayout;
import com.android.camera.ui.RGK_XCRoundRectImageView;
import com.android.camera.ui.RGK_ScrollControlPanelLayout.OnScreenChangeListener;
import com.mediatek.camera.ISettingCtrl;
import com.mediatek.camera.ICameraMode.CameraModeType;
import com.mediatek.camera.setting.preference.ListPreference;

import android.widget.Toast;
import android.view.MotionEvent;

public class ModePicker extends ViewManager implements View.OnClickListener,
        View.OnLongClickListener, View.OnTouchListener {
    private static final String TAG = "ModePicker";

    private ListPreference mModePreference;

    public interface OnModeChangedListener {
        void onModeChanged(int newMode);
    }

    // can not change this sequence
    // Before MODE_VIDEO is "capture mode" for UI,switch "capture mode"
    // remaining view should not show
    public static final int MODE_PHOTO = 0;
    public static final int MODE_HDR = 1;
    public static final int MODE_FACE_BEAUTY = 2;
    public static final int MODE_PANORAMA = 3;
    public static final int MODE_ASD = 4;
    public static final int MODE_PHOTO_PIP = 5;
    public static final int MODE_STEREO_CAMERA = 6;
    public static final int MODE_VIDEO = 7;
    public static final int MODE_VIDEO_PIP = 8;
    public static final int MODE_VIDEO_STEREO = 9;

    public static final int MODE_NUM_ALL = 13;
    public static final int OFFSET = 100;
    private static final int OFFSET_STEREO_PREVIEW = OFFSET;
    private static final int OFFSET_STEREO_SINGLE = OFFSET * 2;

    public static final int MODE_PHOTO_3D = OFFSET_STEREO_PREVIEW + MODE_PHOTO;
    public static final int MODE_VIDEO_3D = OFFSET_STEREO_PREVIEW + MODE_VIDEO;

    public static final int MODE_PHOTO_SGINLE_3D = OFFSET_STEREO_SINGLE + MODE_PHOTO;
    public static final int MODE_PANORAMA_SINGLE_3D = OFFSET_STEREO_SINGLE + MODE_PANORAMA;

    private static final int DELAY_MSG_HIDE_MS = 3000; // 3s
    private static final int MODE_DEFAULT_MARGINBOTTOM = 100;
    private static int MODE_DEFAULT_PADDING;
    private static final int MODE_MIN_COUNTS = 4;
    private LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    // modify for RGK new UI solution by anxiang.xiao 20160506
    /*
     * private static final int[] MODE_ICONS_HIGHTLIGHT = new int[MODE_NUM_ALL];
     * private static final int[] MODE_ICON_ORDER = { MODE_PHOTO,
     * MODE_STEREO_CAMERA, MODE_PHOTO_PIP, MODE_FACE_BEAUTY, MODE_PANORAMA};
     * static { MODE_ICONS_HIGHTLIGHT[MODE_PHOTO] =
     * R.drawable.ic_mode_photo_focus; MODE_ICONS_HIGHTLIGHT[MODE_FACE_BEAUTY] =
     * R.drawable.ic_mode_facebeauty_focus; MODE_ICONS_HIGHTLIGHT[MODE_PANORAMA]
     * = R.drawable.ic_mode_panorama_focus;
     * MODE_ICONS_HIGHTLIGHT[MODE_PHOTO_PIP] = R.drawable.ic_mode_pip_focus;
     * MODE_ICONS_HIGHTLIGHT[MODE_STEREO_CAMERA] =
     * R.drawable.ic_mode_refocus_focus; }; private static final int[]
     * MODE_ICONS_NORMAL = new int[MODE_NUM_ALL]; static {
     * MODE_ICONS_NORMAL[MODE_PHOTO] = R.drawable.ic_mode_photo_normal;
     * MODE_ICONS_NORMAL[MODE_FACE_BEAUTY] =
     * R.drawable.ic_mode_facebeauty_normal; MODE_ICONS_NORMAL[MODE_PANORAMA] =
     * R.drawable.ic_mode_panorama_normal; MODE_ICONS_NORMAL[MODE_PHOTO_PIP] =
     * R.drawable.ic_mode_pip_normal; MODE_ICONS_NORMAL[MODE_STEREO_CAMERA] =
     * R.drawable.ic_mode_refocus_normal; };
     */

    // private final RotateImageView[] mModeViews = new
    // RotateImageView[MODE_NUM_ALL];
    private ModePickerScrollView mScrollView;
    private int mCurrentMode = -1;
    private OnModeChangedListener mModeChangeListener;
    private OnScreenToast mModeToast;
    private int mDisplayWidth;
    private int mDisplayHeight;

    private int mModeWidth;
    private int mModeMarginBottom = MODE_DEFAULT_MARGINBOTTOM;

    // add for RGK new UI solution by anxiang.xiao 20160506

    public static final int MODE_EXPOSURE = 5;
    public static final int MODE_NIGHT = 6;
    public static final int MODE_CLEAR = 7;
    public static final int MODE_PROFESSIONAL = 8;

    public static final int MODE_SLOWMOTION = 9;

    // public static final int MODE_FACEART = 10;//gangyun tech add
    // public static final int MODE_NUM_ALL = 9;

    // add for smile shot & voice capture mode
    public static final int MODE_SMILE_SHOT = 11;
    public static final int MODE_VOICE_CAPTURE = 12;

    public static final int MODE_NUM_ALL_ADDITIONAL = 13;
    // add for smile shot & voice capture mode
    public static final String KEY_SMILE_SHOT = "pref_smile_shot_key";
    public static final String KEY_VOICE = "pref_voice_key";

    public static final String KEY_SLOW_MOTION = "pref_slow_motion_key";

    public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
    public static final String KEY_VIDEO_QUALITY = "pref_video_quality_key";
    public static final String KEY_HDR = "pref_hdr_key";
    public static final String ENTRY_NIGHT = "night";
    public static final String ENTRY_AUTO = "auto";
    public static final String ENTRY_ON = "on";
    public static final String ENTRY_OFF = "off";

    private ListPreference mEffectPreference;
    protected ISettingCtrl mISettingCtrl;

    CameraActivity mContext;

    private PickerListener mListener;

    private float outLeftX_1;
    private float outLeftY_1;
    private float outRightX_1;
    private float outRightY_1;

    private float outLeftX_2;
    private float outLeftY_2;
    private float outRightX_2;
    private float outRightY_2;

    private final RGK_XCRoundRectImageView[] mModeViewsAdditional = new RGK_XCRoundRectImageView[MODE_NUM_ALL_ADDITIONAL];
    private final RGK_XCRoundRectImageView[] mModeViews = new RGK_XCRoundRectImageView[MODE_NUM_ALL];

    private static final int[] MODE_ICONS_HIGHTLIGHT = new int[MODE_NUM_ALL];
    private static final int[] MODE_ICON_ORDER = {
            MODE_PHOTO, MODE_STEREO_CAMERA, MODE_PHOTO_PIP,
            MODE_FACE_BEAUTY, MODE_PANORAMA
    };
    static {
        MODE_ICONS_HIGHTLIGHT[MODE_PHOTO] = R.drawable.rgk_photo_hi;
        MODE_ICONS_HIGHTLIGHT[MODE_FACE_BEAUTY] = R.drawable.rgk_facebuty_hi;
        MODE_ICONS_HIGHTLIGHT[MODE_PANORAMA] = R.drawable.rgk_panorama_hi;
        MODE_ICONS_HIGHTLIGHT[MODE_PHOTO_PIP] = R.drawable.rgk_pip_hi;
        MODE_ICONS_HIGHTLIGHT[MODE_STEREO_CAMERA] = R.drawable.ic_mode_refocus_focus;
    };
    private static final int[] MODE_ICONS_NORMAL = new int[MODE_NUM_ALL];
    static {
        MODE_ICONS_NORMAL[MODE_PHOTO] = R.drawable.rgk_photo;
        MODE_ICONS_NORMAL[MODE_FACE_BEAUTY] = R.drawable.rgk_facebuty;
        MODE_ICONS_NORMAL[MODE_PANORAMA] = R.drawable.rgk_panorama;
        MODE_ICONS_NORMAL[MODE_PHOTO_PIP] = R.drawable.rgk_pip;
        MODE_ICONS_NORMAL[MODE_STEREO_CAMERA] = R.drawable.ic_mode_refocus_normal;
    };
    private static final int[] ADDTION_MODE_ICONS_HIGHTLIGHT = new int[MODE_NUM_ALL];
    static {
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_EXPOSURE] = R.drawable.rgk_exposure_hi;
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_NIGHT] = R.drawable.rgk_night_hi;
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_CLEAR] = R.drawable.rgk_clear_hi;
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_HDR] = R.drawable.rgk_hdr_hi;

        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_PROFESSIONAL] = R.drawable.rgk_prefession_hi;

        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_SLOWMOTION] = R.drawable.rgk_slowmotion_hi;
        // ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_FACEART] =
        // R.drawable.gy_ic_mode_faceart_focus; //gangyun tech add
        // add for smile shot & voice capture mode
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_SMILE_SHOT] = R.drawable.rgk_smile_shot_hi;
        ADDTION_MODE_ICONS_HIGHTLIGHT[MODE_VOICE_CAPTURE] = R.drawable.rgk_voice_capture_hi;
    };

    private static final int[] ADDTION_MODE_ICONS_NORMAL = new int[MODE_NUM_ALL];
    static {
        ADDTION_MODE_ICONS_NORMAL[MODE_EXPOSURE] = R.drawable.rgk_exposure;
        ADDTION_MODE_ICONS_NORMAL[MODE_NIGHT] = R.drawable.rgk_night;
        ADDTION_MODE_ICONS_NORMAL[MODE_CLEAR] = R.drawable.rgk_clear;
        ADDTION_MODE_ICONS_NORMAL[MODE_HDR] = R.drawable.rgk_hdr;

        ADDTION_MODE_ICONS_NORMAL[MODE_PROFESSIONAL] = R.drawable.rgk_prefession;

        ADDTION_MODE_ICONS_NORMAL[MODE_SLOWMOTION] = R.drawable.rgk_slowmotion;
        // ADDTION_MODE_ICONS_NORMAL[MODE_FACEART] =
        // R.drawable.gy_ic_mode_faceart_normal; //gangyun tech add

        // add for smile shot & voice capture mode
        ADDTION_MODE_ICONS_NORMAL[MODE_SMILE_SHOT] = R.drawable.rgk_smile_shot;
        ADDTION_MODE_ICONS_NORMAL[MODE_VOICE_CAPTURE] = R.drawable.rgk_voice_capture;
    };

    private int mAddToPanelNums;
    private final int mOneScreenNums = 9;
    private RGK_PageControlView pageControl;
    private RGK_ScrollControlPanelLayout scrollControlLayout;
    RGK_ControlPanelLayout controlPanelLayout1;
    RGK_ControlPanelLayout controlPanelLayout2;

    private int mSettingTimeLapseTime;
    private boolean mflag = false;
    private boolean mControlModeFlag = false;
    private static boolean isPipLastMode = false;
    private static int lastAddtionMode = -1;

    public boolean getControlModeFlagClick() {
        return mControlModeFlag;
    }
    // add end

    public ModePicker(CameraActivity context) {
        super(context, VIEW_LAYER_OVERLAY);

        mContext = context;
        MODE_DEFAULT_PADDING = mContext.getResources()
                .getDimensionPixelSize(R.dimen.camera_mode_default_padding);

    }

    public int getCurrentMode() {
        return mCurrentMode;
    }

    private void setRealMode(int mode) {
        Log.d(TAG, "setRealMode(" + mode + ") mCurrentMode=" + mCurrentMode);

        if (mode == MODE_PHOTO_PIP) {
        }
        // in photo mode, if the hdr, asd, smile shot, gesture shot is on, we
        // should set the current mode is hdr or asd or smile shot. in hdr, asd,
        // smile shot, gesture shot mode if its values is off in
        // sharepreference,
        // we should set the current mode
        // as photo mode
        /*
         * if (mode == MODE_PHOTO || mode == MODE_HDR || mode == MODE_ASD) {
         * mode = getRealMode(mModePreference); }
         */

        if (mCurrentMode != mode) {
            mCurrentMode = mode;
            highlightCurrentMode();
            notifyModeChanged();
            if (mModeToast != null) {
                mModeToast.cancel();
            }
        } else {
            // if mode do not change, we should reset ModePicker view enabled
            setEnabled(true);
        }
    }

    private void setRealModeNoHi(int mode) {
        Log.d(TAG, "setRealMode(" + mode + ") mCurrentMode=" + mCurrentMode);

        if (mode == MODE_PHOTO_PIP) {
        }
        // in photo mode, if the hdr, asd, smile shot, gesture shot is on, we
        // should set the current mode is hdr or asd or smile shot. in hdr, asd,
        // smile shot, gesture shot mode if its values is off in
        // sharepreference,
        // we should set the current mode
        // as photo mode
        /*
         * if (mode == MODE_PHOTO || mode == MODE_HDR || mode == MODE_ASD) {
         * mode = getRealMode(mModePreference); }
         */

        if (mCurrentMode != mode) {
            mCurrentMode = mode;
            // highlightCurrentMode();
            notifyModeChanged();
            if (mModeToast != null) {
                mModeToast.cancel();
            }
        } else {
            // if mode do not change, we should reset ModePicker view enabled
            setEnabled(true);
        }
    }

    public void setCurrentMode(int mode) {
        int realmode = getModeIndex(mode);
        if (getContext().isStereoMode()) {
            if (FeatureSwitcher.isStereoSingle3d()) {
                realmode += OFFSET_STEREO_SINGLE;
            } else {
                realmode += OFFSET_STEREO_PREVIEW;
            }
        }
        Log.i(TAG, "setCurrentMode(" + mode + ") realmode=" + realmode);
        setRealMode(realmode);
    }

    public void setCurrentModeNoHi(int mode) {
        int realmode = getModeIndex(mode);
        if (getContext().isStereoMode()) {
            if (FeatureSwitcher.isStereoSingle3d()) {
                realmode += OFFSET_STEREO_SINGLE;
            } else {
                realmode += OFFSET_STEREO_PREVIEW;
            }
        }
        Log.i(TAG, "setCurrentMode(" + mode + ") realmode=" + realmode);
        setRealModeNoHi(realmode);
    }

    private void nohighlightAllMode() {
        int index = getModeIndex(mCurrentMode);

        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null)
                mModeViews[i].setImageResource(MODE_ICONS_NORMAL[i]);
        }

        for (int i = 0; i < MODE_NUM_ALL_ADDITIONAL; i++) {
            if (mModeViewsAdditional[i] != null)
                mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_NORMAL[i]);
        }
    }

    private void highlightCurrentMode() {
        int index = getModeIndex(mCurrentMode);
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                // modify for avoid finish video mode jump to normal mode ui
                // change by anxiang.xiao 20160616 start
                if (!mflag) {
                    if (i == index) {
                        mModeViews[i].setImageResource(MODE_ICONS_HIGHTLIGHT[i]);
                    } else {
                        mModeViews[i].setImageResource(MODE_ICONS_NORMAL[i]);
                    }
                } else {
                    mModeViews[i].setImageResource(MODE_ICONS_NORMAL[i]);
                }
            }

            // add for RGK new UI solution by anxiang.xiao 20160506
            if (mModeViewsAdditional[i] != null) {
                if (mflag) {
                    if (lastAddtionMode == i)
                        mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_HIGHTLIGHT[i]);
                    else
                        mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_NORMAL[i]);
                } else {
                    mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_NORMAL[i]);
                }
                /*
                 * if (i == index) { mModeViewsAdditional[i].setImageResource(
                 * ADDTION_MODE_ICONS_HIGHTLIGHT[i]); } else {
                 * mModeViewsAdditional[i].setImageResource(
                 * ADDTION_MODE_ICONS_NORMAL[i]); }
                 */
            }
            // modify for avoid finish video mode jump to normal mode ui change
            // by anxiang.xiao 20160616 end

            if (MODE_HDR == index || MODE_ASD == index
                    || (FeatureSwitcher.isVfbEnable() && MODE_FACE_BEAUTY == index)) {
                // mModeViews[MODE_PHOTO].setImageResource(MODE_ICONS_HIGHTLIGHT[MODE_PHOTO]);
            }
        }
    }

    public int getModeIndex(int mode) {
        int index = mode % OFFSET;
        Log.d(TAG, "getModeIndex(" + mode + ") return " + index);
        return index;
    }

    public void setListener(OnModeChangedListener l) {
        mModeChangeListener = l;
    }

    /*
     * @Override protected View getView() { clearListener(); View view =
     * inflate(R.layout.mode_picker); mScrollView = (ModePickerScrollView)
     * view.findViewById(R.id.mode_picker_scroller); mModeViews[MODE_PHOTO] =
     * (RotateImageView) view.findViewById(R.id.mode_photo);
     * mModeViews[MODE_PHOTO_PIP] = (RotateImageView)
     * view.findViewById(R.id.mode_photo_pip); mModeViews[MODE_STEREO_CAMERA] =
     * (RotateImageView) view .findViewById(R.id.mode_stereo_camera);
     * mModeViews[MODE_FACE_BEAUTY] = (RotateImageView)
     * view.findViewById(R.id.mode_face_beauty); mModeViews[MODE_PANORAMA] =
     * (RotateImageView) view.findViewById(R.id.mode_panorama); DisplayMetrics
     * metrics = getContext().getResources().getDisplayMetrics(); mDisplayWidth
     * = Math.min(metrics.widthPixels, metrics.heightPixels); mModeWidth =
     * getModeWidth(); mModeMarginBottom = getDefaultMarginBottom();
     * applyListener(); highlightCurrentMode(); return view; }
     */

    // add for judege is the click event happend in the scroll layout empty eare
    // by anxiang.xiao 20160525

    public boolean isInPage1EmptyArea(float x, float y) {
        if (y > mDisplayWidth)
            return true;
        if (y > outLeftY_1 + mDisplayWidth / 3)
            return true;

        if (x > outLeftX_1 && x < mDisplayWidth && y > outLeftY_1 && y < mDisplayHeight)
            return true;

        return false;
    }

    public boolean isInPage2EmptyArea(float x, float y) {
        if (y > mDisplayWidth)
            return true;
        if (y > outLeftY_2 + mDisplayWidth / 3)
            return true;

        if (x > outLeftX_2 && x < mDisplayWidth && y > outLeftY_2 && y < mDisplayHeight)
            return true;

        return false;
    }

    // modify for RGK new UI solution by anxiang.xiao 20160506
    protected View getView() {
        clearListener();
        View view = inflate(R.layout.rgk_mode_panel_layout);

        scrollControlLayout = (RGK_ScrollControlPanelLayout) view.findViewById(R.id.ll);

        controlPanelLayout1 = new RGK_ControlPanelLayout(getContext());
        // controlPanelLayout1.setBackgroundColor(Color.GREEN);

        controlPanelLayout2 = new RGK_ControlPanelLayout(getContext());
        // controlPanelLayout2.setBackgroundColor(Color.GRAY);

        DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        mDisplayWidth = Math.min(metrics.widthPixels, metrics.heightPixels);
        mDisplayHeight = Math.max(metrics.widthPixels, metrics.heightPixels);

        Log.i(TAG,
                "mDisplayWidth:" + metrics.widthPixels + ",mDisplayHeight:" + metrics.heightPixels);

        controlPanelLayout1.setmCellHeight(mDisplayWidth / 3);
        controlPanelLayout1.setmCellWidth(mDisplayWidth / 3);

        controlPanelLayout2.setmCellHeight(mDisplayWidth / 3);
        controlPanelLayout2.setmCellWidth(mDisplayWidth / 3);

        scrollControlLayout.setOnScreenChangeListener(new OnScreenChangeListener() {
            public void onScreenChange(int currentIndex) {
                // TODO Auto-generated method stub
                // generatePageControl(currentIndex);
            }
        });

        for (int i = 0; i < MODE_NUM_ALL; i++) {

            mModeViews[i] = null;

        }

        // mScrollView = (ModePickerScrollView)
        // view.findViewById(R.id.mode_picker_scroller);
        mModeViews[MODE_PHOTO] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViews[MODE_PHOTO]
                .setDrawTextTitle(getContext().getResources().getString(R.string.photo_mode_draw));
        mModeViews[MODE_PHOTO].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_camera));

        mModeViews[MODE_PHOTO_PIP] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViews[MODE_PHOTO_PIP]
                .setDrawTextTitle(getContext().getResources().getString(R.string.pip_mode_draw));
        mModeViews[MODE_PHOTO_PIP].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_pip));

        mModeViews[MODE_STEREO_CAMERA] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViews[MODE_STEREO_CAMERA].setDrawTextTitle("Stereo camera");
        mModeViews[MODE_STEREO_CAMERA].setContentDescription(getContext().getResources()
                .getString(R.string.accessibility_switch_to_dual_camera));
        /*
         * mModeViews[MODE_FACE_BEAUTY] = new
         * RGK_XCRoundRectImageView(getContext(), 0) ;
         * mModeViews[MODE_FACE_BEAUTY].setDrawTextTitle(getContext().
         * getResources().getString(R.string.facebuty_mode_draw));
         * mModeViews[MODE_FACE_BEAUTY].setContentDescription(getContext().
         * getResources().getString(R.string.accessibility_switch_to_face_beauty
         * ));
         */
        mModeViews[MODE_PANORAMA] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViews[MODE_PANORAMA].setDrawTextTitle(
                getContext().getResources().getString(R.string.panorama_mode_draw));
        mModeViews[MODE_PANORAMA].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_panorama));

        mAddToPanelNums = 0;

        // remove photo/normal view for the exit func instead
        for (int i = 1; i < MODE_NUM_ALL; i++) {
            // for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                boolean visible = ModeChecker.getModePickerVisible(getContext(), getContext()
                        .getCameraId(), i);

                if (MODE_FACE_BEAUTY == i && FeatureSwitcher.isVfbEnable()) {
                    visible = false;
                }
                // remove facety mode show forcely by anxiang.xiao temply
                if (MODE_FACE_BEAUTY == i) {
                    visible = false;
                }

                if (visible) {
                    if (mAddToPanelNums < mOneScreenNums)
                        controlPanelLayout1.addView(mModeViews[i]);
                    else
                        controlPanelLayout2.addView(mModeViews[i]);

                    mAddToPanelNums++;

                }
            }

        }
        // add end

        // add by anxiang.xiao start

        for (int i = 0; i < MODE_NUM_ALL; i++) {

            mModeViewsAdditional[i] = null;

        }
        mModeViewsAdditional[MODE_HDR] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViewsAdditional[MODE_HDR]
                .setDrawTextTitle(getContext().getResources().getString(R.string.hdr_mode_draw));
        mModeViewsAdditional[MODE_HDR].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_hdr));

        mModeViewsAdditional[MODE_EXPOSURE] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViewsAdditional[MODE_EXPOSURE].setDrawTextTitle(
                getContext().getResources().getString(R.string.exposure_mode_draw));
        mModeViewsAdditional[MODE_EXPOSURE].setContentDescription(getContext().getResources()
                .getString(R.string.accessibility_switch_to_long_exposure));

        mModeViewsAdditional[MODE_CLEAR] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViewsAdditional[MODE_CLEAR]
                .setDrawTextTitle(getContext().getResources().getString(R.string.clear_mode_draw));
        mModeViewsAdditional[MODE_CLEAR].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_hd));

        /*
         * mModeViewsAdditional[MODE_CLEAR] = new
         * RGK_XCRoundRectImageView(getContext(), 0) ;
         * mModeViewsAdditional[MODE_CLEAR].setDrawTextTitle(getContext().
         * getResources().getString(R.string.clear_mode_draw));
         * mModeViewsAdditional[MODE_CLEAR].setContentDescription(getContext().
         * getResources().getString(R.string.accessibility_switch_to_hd));
         */

        // add for smile shot & voice capture mode
        /*
         * mModeViewsAdditional[MODE_SMILE_SHOT] = new
         * RGK_XCRoundRectImageView(getContext(), 0) ;
         * mModeViewsAdditional[MODE_SMILE_SHOT].setDrawTextTitle(getContext().
         * getResources().getString(R.string.smile_shot_draw));
         */
        // mModeViewsAdditional[MODE_SMILE_SHOT].setContentDescription(getContext().getResources().getString(R.string.smileshot_guide_capture));
        /*
         * mModeViewsAdditional[MODE_VOICE_CAPTURE] = new
         * RGK_XCRoundRectImageView(getContext(), 0) ;
         * mModeViewsAdditional[MODE_VOICE_CAPTURE].setDrawTextTitle(getContext(
         * ).getResources().getString(R.string.voice_capture_draw));
         */
        // mModeViewsAdditional[MODE_VOICE_CAPTURE].setContentDescription(getContext().getResources().getString(R.string.voice_guide));

        // bug-id:DWYQYSB-157 remove slomotion temply for 6580 not support
        // slowmotion func

        mModeViewsAdditional[MODE_SLOWMOTION] = new RGK_XCRoundRectImageView(getContext(), 0);
        mModeViewsAdditional[MODE_SLOWMOTION].setDrawTextTitle(
                getContext().getResources().getString(R.string.slowmotion_mode_draw));
        mModeViewsAdditional[MODE_SLOWMOTION].setContentDescription(
                getContext().getResources().getString(R.string.accessibility_switch_to_slowmotion));

        /*
         * mModeViewsAdditional[MODE_NIGHT] = new
         * RGK_XCRoundRectImageView(getContext()) ;
         * mModeViewsAdditional[MODE_NIGHT].setDrawText(getContext().
         * getResources().getString(R.string.night_mode_draw));
         * mModeViewsAdditional[MODE_NIGHT].setContentDescription(getContext().
         * getResources().getString(R.string.accessibility_switch_to_night));
         * mModeViewsAdditional[MODE_PROFESSIONAL] = new
         * RGK_XCRoundRectImageView(getContext(), 0) ;
         * mModeViewsAdditional[MODE_PROFESSIONAL].setDrawTextTitle(getContext()
         * .getResources().getString(R.string.profession_mode_draw));
         * mModeViewsAdditional[MODE_PROFESSIONAL].setContentDescription(
         * getContext().getResources().getString(R.string.
         * accessibility_switch_to_profession));
         */

        for (int i = 0; i < MODE_NUM_ALL_ADDITIONAL; i++) {

            if (mModeViewsAdditional[i] != null) {
                if (mAddToPanelNums < mOneScreenNums)
                    controlPanelLayout1.addView(mModeViewsAdditional[i]);
                else
                    controlPanelLayout2.addView(mModeViewsAdditional[i]);

                mAddToPanelNums++;
            }

        }
        // add for judege is the click event happend in the scroll layout empty
        // eare by anxiang.xiao 20160525
        int addPanel1Count = controlPanelLayout1.getChildCount();
        if (addPanel1Count > 0) {

            scrollControlLayout.addView(controlPanelLayout1);

            if (addPanel1Count % 3 == 1)
                outLeftX_1 = mDisplayWidth / 3;
            else if (addPanel1Count % 3 == 2)
                outLeftX_1 = 2 * (mDisplayWidth / 3);
            else if (addPanel1Count % 3 == 0)
                outLeftX_1 = 0;

            if (addPanel1Count / 3 == 1)
                outLeftY_1 = mDisplayWidth / 3;
            else if (addPanel1Count / 3 == 2)
                outLeftY_1 = 2 * (mDisplayWidth / 3);
            else if (addPanel1Count / 3 == 0)
                outLeftY_1 = 3 * (mDisplayWidth / 3);
            else if (addPanel1Count / 3 == 0)
                outLeftY_1 = 0;

        }

        int addPanel2Count = controlPanelLayout2.getChildCount();
        if (addPanel2Count > 0) {
            scrollControlLayout.addView(controlPanelLayout2);

            if (addPanel2Count % 3 == 1)
                outLeftX_2 = mDisplayWidth / 3;
            else if (addPanel2Count % 3 == 2)
                outLeftX_2 = 2 * (mDisplayWidth / 3);
            else if (addPanel2Count % 3 == 0)
                outLeftX_2 = 0;

            if (addPanel2Count / 3 == 1)
                outLeftY_2 = mDisplayWidth / 3;
            else if (addPanel2Count / 3 == 2)
                outLeftY_2 = 2 * (mDisplayWidth / 3);
            else if (addPanel2Count / 3 == 0)
                outLeftY_2 = 3 * (mDisplayWidth / 3);
            else if (addPanel2Count / 3 == 0)
                outLeftY_2 = 0;
        }

        // add by anxiang.xiao end

        pageControl = (RGK_PageControlView) view.findViewById(R.id.pageControl);
        pageControl.bindScrollViewGroup(scrollControlLayout);

        mModeWidth = getModeWidth();
        mModeMarginBottom = getDefaultMarginBottom();
        applyListener();
        highlightCurrentMode();
        return view;
    }

    private void applyListener() {
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                mModeViews[i].setOnClickListener(this);
                mModeViews[i].setOnLongClickListener(this);
            }

            // add for new UI solotion by anxiang.xiao 20160506
            if (mModeViewsAdditional[i] != null) {
                mModeViewsAdditional[i].setOnClickListener(this);
                mModeViewsAdditional[i].setOnLongClickListener(this);
            }

            // add end
        }
    }

    private void clearListener() {
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                mModeViews[i].setOnClickListener(null);
                mModeViews[i].setOnLongClickListener(null);
                mModeViews[i] = null;
            }

            // add for new UI solotion by anxiang.xiao 20160506
            if (mModeViewsAdditional[i] != null) {
                mModeViewsAdditional[i].setOnClickListener(null);
                mModeViewsAdditional[i].setOnLongClickListener(null);
                mModeViewsAdditional[i] = null;
            }

            // add end
        }
    }

    // add for new UI solotion by anxiang.xiao 20160506
    private void addtionModeHighlight(int mode) {
        int index = getModeIndex(mode);
        for (int i = 0; i < MODE_NUM_ALL; i++) {

            if (mModeViews[i] != null) {
                mModeViews[i].setImageResource(MODE_ICONS_NORMAL[i]);
            }

            if (mModeViewsAdditional[i] != null) {
                if (i == mode) {
                    mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_HIGHTLIGHT[i]);
                } else {
                    mModeViewsAdditional[i].setImageResource(ADDTION_MODE_ICONS_NORMAL[i]);
                }
            }

        }
    }
    // add end

    public void setListener(PickerListener listener) {
        mListener = listener;
    }

    // for add addtional mode switch by anxiang.xiao 20160520
    private void openNightMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SCENE_MODE);

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(ENTRY_NIGHT)) {
            mContext.onSettingChanged(KEY_SCENE_MODE, ENTRY_NIGHT);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_NIGHT);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    private void openExposureMode() {

    }

    private void openHdMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_VIDEO_QUALITY);
        int len = mEffectPreference.getEntryValues().length;
        String qualityHighest = mEffectPreference.getEntryValues()[len - 1].toString();
        String qualityDefault = mEffectPreference.getDefaultValue();

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(qualityHighest)) {
            mContext.onSettingChanged(KEY_VIDEO_QUALITY, qualityHighest);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(qualityHighest);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);

        }
    }

    private void openHdrMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_HDR);

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_HDR, ENTRY_ON);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_ON);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);

            mListener.onHdrPicked(ENTRY_ON);
        }
    }

    private void openSlowmotionMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SLOW_MOTION);

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_SLOW_MOTION, ENTRY_ON);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_ON);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);

            mListener.onSlowMotionPicked(ENTRY_ON);
        }
    }

    private void openProfessionMode() {
        if (!mContext.getRGKProManager().isShowing()) {
            mContext.getRGKProManager().show();
        }
    }

    // add for smile shot & voice capture mode
    private void openSmileShotMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SMILE_SHOT);

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_SMILE_SHOT, ENTRY_ON);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_ON);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    private void openVoiceCaptureMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_VOICE);

        if (mEffectPreference != null && !mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_VOICE, ENTRY_ON);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_ON);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    private void closeNightMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SCENE_MODE);

        if (mEffectPreference != null && mEffectPreference.getValue().equals(ENTRY_NIGHT)) {
            mContext.onSettingChanged(KEY_SCENE_MODE, ENTRY_AUTO);

            mEffectPreference.setValue(ENTRY_AUTO);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    private void closeExposureMode() {

    }

    private void closeHdMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_VIDEO_QUALITY);
        int len = mEffectPreference.getEntryValues().length;
        String qualityHighest = mEffectPreference.getEntryValues()[len - 1].toString();
        String qualityDefault = mEffectPreference.getDefaultValue();

        if (mEffectPreference != null && mEffectPreference.getValue().equals(qualityHighest)) {
            mContext.onSettingChanged(KEY_VIDEO_QUALITY, qualityDefault);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());
            mEffectPreference.setValue(qualityDefault);
            mContext.getCameraDeviceCtrl().applyParameters(false);
            mContext.notifyPreferenceChanged(mEffectPreference);
        }
    }

    private void closeHdrMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_HDR);

        if (mEffectPreference != null && mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_HDR, ENTRY_OFF);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_OFF);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);

            mListener.onHdrPicked(ENTRY_OFF);
        }
    }

    private void closeSlowmotionMode() {

        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SLOW_MOTION);

        if (mEffectPreference != null && mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_SLOW_MOTION, ENTRY_OFF);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_OFF);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
            mListener.onHdrPicked(ENTRY_OFF);
        }
    }

    private void closeProfessionMode() {

        if (mContext.getRGKProManager().isShowing()) {
            mContext.getRGKProManager().hide();
        }
    }

    // add for smile shot & voice capture mode
    private void closeSmileShotMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_SMILE_SHOT);

        if (mEffectPreference != null && mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_SMILE_SHOT, ENTRY_OFF);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_OFF);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    private void closeVoiceCaptureMode() {
        mISettingCtrl = mContext.getISettingCtrl();
        mEffectPreference = mISettingCtrl.getListPreference(KEY_VOICE);

        if (mEffectPreference != null && mEffectPreference.getValue().equals(ENTRY_ON)) {
            mContext.onSettingChanged(KEY_VOICE, ENTRY_OFF);
            // mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].toString());

            mEffectPreference.setValue(ENTRY_OFF);

            mContext.getCameraDeviceCtrl().applyParameters(false);

            mContext.notifyPreferenceChanged(mEffectPreference);
        }

    }

    public void closeAllAdditonalMode() {
        closeSlowmotionMode();
        closeHdrMode();
        closeNightMode();
        closeHdMode();
        closeProfessionMode();
        closeExposureMode();
        // closeSmileShotMode();
        // closeVoiceCaptureMode();
    }

    private void switchToAddtionalMode(int mode) {
        // TODO Auto-generated method stub
        int currentMode = getCurrentMode();

        if (currentMode == MODE_PHOTO_PIP || currentMode == MODE_VIDEO_PIP)
            setCurrentModeNoHi(MODE_VIDEO);
        if (currentMode != MODE_PHOTO)
            setCurrentModeNoHi(MODE_PHOTO);

        switch (mode) {
            case MODE_HDR:
                openHdrMode();

                closeSlowmotionMode();
                closeNightMode();
                closeHdMode();
                closeProfessionMode();
                closeExposureMode();
                // closeSmileShotMode();
                // closeVoiceCaptureMode();

                break;

            case MODE_SLOWMOTION:
                openSlowmotionMode();

                closeHdrMode();
                closeNightMode();
                closeHdMode();
                closeProfessionMode();
                closeExposureMode();
                closeSmileShotMode();
                closeVoiceCaptureMode();

                break;

            case MODE_EXPOSURE:

                openExposureMode();

                closeSlowmotionMode();
                closeNightMode();
                closeHdMode();
                closeProfessionMode();
                closeHdrMode();
                // closeSmileShotMode();
                // closeVoiceCaptureMode();

                break;

            case MODE_NIGHT:

                openNightMode();

                closeSlowmotionMode();
                closeExposureMode();
                closeHdMode();
                closeProfessionMode();
                closeHdrMode();
                // closeSmileShotMode();
                // closeVoiceCaptureMode();

                break;

            case MODE_CLEAR:

                openHdMode();

                closeSlowmotionMode();
                closeExposureMode();
                closeNightMode();
                closeProfessionMode();
                closeHdrMode();
                // closeSmileShotMode();
                // closeVoiceCaptureMode();

                break;

            case MODE_PROFESSIONAL:

                openProfessionMode();

                closeSlowmotionMode();
                closeExposureMode();
                closeNightMode();
                closeHdMode();
                closeHdrMode();
                // closeSmileShotMode();
                // closeVoiceCaptureMode();

                break;

            // gangyun tech add
            /*
             * case MODE_FACEART: openGyBeautyMode(); closeSlowmotionMode();
             * closeExposureMode(); closeNightMode(); closeProfessionMode();
             * closeHdMode(); closeHdrMode(); break;
             */
            // gangyun tech add
            // add for smile shot & voice capture mode
            case MODE_SMILE_SHOT:
                openSmileShotMode();

                closeHdMode();
                closeSlowmotionMode();
                closeExposureMode();
                closeNightMode();
                closeProfessionMode();
                closeHdrMode();
                closeVoiceCaptureMode();

                break;

            case MODE_VOICE_CAPTURE:

                openVoiceCaptureMode();

                closeSlowmotionMode();
                closeExposureMode();
                closeNightMode();
                closeHdMode();
                closeHdrMode();
                closeProfessionMode();
                closeSmileShotMode();

                break;
            default:
                break;
        }

    }
    // for add addtional mode switch by anxiang.xiao 20160520 end

    // gangyun tech add
    /*
     * private void closeGyBeautyMode() { mISettingCtrl =
     * mContext.getISettingCtrl(); mEffectPreference =
     * mISettingCtrl.getListPreference(KEY_GYBEAUTY_MODE); if (mEffectPreference
     * !=null && mEffectPreference.getValue().equals(ENTRY_ON)) {
     * mContext.onSettingChanged(KEY_GYBEAUTY_MODE, ENTRY_OFF);
     * //mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].
     * toString()); mEffectPreference.setValue(ENTRY_OFF);
     * mContext.getCameraDeviceCtrl().applyParameters(false);
     * mContext.notifyPreferenceChanged(mEffectPreference);
     * mListener.onHdrPicked(ENTRY_OFF); } } private void openGyBeautyMode() {
     * mISettingCtrl = mContext.getISettingCtrl(); mEffectPreference =
     * mISettingCtrl.getListPreference(KEY_GYBEAUTY_MODE); if (mEffectPreference
     * !=null && !mEffectPreference.getValue().equals(ENTRY_ON)) {
     * mContext.onSettingChanged(KEY_GYBEAUTY_MODE, ENTRY_ON);
     * //mEffectPreference.setValue(mEffectPreference.getEntryValues()[i].
     * toString()); mEffectPreference.setValue(ENTRY_ON);
     * mContext.getCameraDeviceCtrl().applyParameters(false);
     * mContext.notifyPreferenceChanged(mEffectPreference);
     * mListener.onHdrPicked(ENTRY_ON); } }
     */
    // gangyun tech add end

    public boolean getAddtionClickFlag() {
        // TODO Auto-generated method stub
        return mflag;
    }

    public void pipUiRestore() {
        if (isPipLastMode) {
            mContext.getShutterManager().restorePhotoButtonX();
            mContext.getShutterManager().restoreVideoButtonX();

        }
        isPipLastMode = false;
    }

    @Override
    public void onClick(View view) {
        Log.d(TAG, "onClick(" + view + ") isEnabled()=" + isEnabled() + ", view.isEnabled()="
                + view.isEnabled() + ", getContext().isFullScreen()=" + getContext().isFullScreen()
                + ",mCurrentMode = " + mCurrentMode);
        if (FeatureSwitcher.isVfbEnable() && mCurrentMode == MODE_FACE_BEAUTY
                && view == mModeViews[MODE_PHOTO]) {
            Log.i(TAG, "onClick(,will return");
            return;
        }
        setEnabled(false);
        if (getContext().isFullScreen()) {
            for (int i = 0; i < MODE_NUM_ALL; i++) {
                // modify for RGK new UI solution by anxiang.xiao 20160506
                if (mModeViews[i] == view) {
                    lastAddtionMode = -1;
                    pipUiRestore();
                    closeAllAdditonalMode();

                    mflag = false;

                    if (i == MODE_PHOTO && getCurrentMode() == MODE_PHOTO)
                        highlightCurrentMode();
                    else
                        setCurrentMode(i);

                    if (i == MODE_PANORAMA) {
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                    } else if (i == MODE_PHOTO_PIP) {
                        isPipLastMode = true;
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                        mContext.getShutterManager().movePhotoButtonX();
                        mContext.getShutterManager().moveVideoButtonX();
                    } else if (i == MODE_PHOTO) {
                        mContext.getBottomModePicker().show();
                        mContext.getBottomModePicker().setNormalScreenDefault();
                    }

                    ((CameraActivity) getContext()).getModePicker().hide();
//                    ((CameraActivity) getContext()).getRGKSettingIndictorPickerOnePage().hide();
                    // ((CameraActivity)getContext()).getRGKSettingPicker().hide();
                    // ((CameraActivity)getContext()).getRGKSettingPicker().hideAllSubSetting();
                    if (i == MODE_PHOTO)
                        mControlModeFlag = false;
                    else
                        mControlModeFlag = true;

                    break;
                }

                if (mModeViewsAdditional[i] == view) {
                    pipUiRestore();
                    lastAddtionMode = i;

                    addtionModeHighlight(i);

                    // ((CameraActivity)getContext()).showCaptureAllViews();

                    ((CameraActivity) getContext()).getModePicker().hide();
//                    ((CameraActivity) getContext()).getRGKSettingIndictorPickerOnePage().hide();
                    // ((CameraActivity)getContext()).getRGKSettingPicker().hide();
                    // ((CameraActivity)getContext()).getRGKSettingPicker().hideAllSubSetting();

                    switchToAddtionalMode(i);

                    if (i == MODE_HDR) {
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                    } else if (i == MODE_EXPOSURE) {
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                    } else if (i == MODE_SMILE_SHOT) { // add for smile shot &
                                                       // voice capture mode
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                    } else if (i == MODE_VOICE_CAPTURE) { // add for smile shot
                                                          // & voice capture
                                                          // mode
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringPhotoTofront();
                    } else if (i == MODE_CLEAR) {
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringVideoTofront();
                    } else if (i == MODE_SLOWMOTION) {
                        mContext.getBottomModePicker().hide();
                        mContext.getShutterManager().bringVideoTofront();
                    }
                    // gangyun tech add
                    /*
                     * else if(i == MODE_FACEART){
                     * mContext.getBottomModePicker().hide();
                     * mContext.getShutterManager().bringPhotoTofront(); }
                     */
                    // gangyun tech add end

                    mflag = true;
                    mControlModeFlag = true;
                    break;
                }

                // modify for RGK new UI solution by anxiang.xiao 20160506 end
            }
            Log.i(TAG, "onClick,isCameraOpened:" + getContext().isCameraOpened());
            if (getContext().isCameraOpened()) {
                setEnabled(true);
            }
        } else {
            // if the is not full screen, we should reset PickMode view enable
            setEnabled(true);
        }

        mContext.showBottomAllExceptBottomPicker();

        if (view.getContentDescription() != null) {
            if (mModeToast == null) {
                mModeToast = OnScreenToast.makeText(getContext(), view.getContentDescription());
            } else {
                mModeToast.setText(view.getContentDescription());
            }
            mModeToast.showToast();
        }
    }

    public void hideToast() {
        Log.i(TAG, "hideToast(), mModeToast:" + mModeToast);
        if (mModeToast != null) {
            mModeToast.hideToast();
        }
    }

    // modify new RGK new UI solution by anxiang.xiao 20160506
    // private void notifyModeChanged() {
    public void notifyModeChanged() {
        if (mModeChangeListener != null) {
            mModeChangeListener.onModeChanged(getCurrentMode());
        }
    }

    // add for self notify
    public void notifyModeChanged2(int mode) {
        if (mModeChangeListener != null) {
            mModeChangeListener.onModeChanged(mode);
        }
    }
    // add & modify end

    public void onRefresh() {
        Log.d(TAG, "onRefresh() mCurrentMode=" + mCurrentMode);
        // get counts of mode supported by back camera and compute the margin
        // bottom between mode icon.
        int supportModes = ModeChecker.modesShowInPicker(getContext(), 0);
        if (supportModes < MODE_MIN_COUNTS && supportModes > 1) {
            mModeMarginBottom = (mDisplayWidth - supportModes * mModeWidth) / (supportModes - 1);
        }
        Log.d(TAG, "mModeMarginBottom:" + mModeMarginBottom);
        mLayoutParams.setMargins(0, 0, 0, 0);

        int visibleCount = 0;
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                boolean visible = ModeChecker.getModePickerVisible(getContext(), getContext()
                        .getCameraId(), i);
                // check vFB
                // if vFB support, FB not need show in the mode picker line
                if (MODE_FACE_BEAUTY == i && FeatureSwitcher.isVfbEnable()) {
                    visible = false;
                }
                mModeViews[i].setVisibility(visible ? View.VISIBLE : View.GONE);
                mModeViews[i].setLayoutParams(mLayoutParams);
                mModeViews[i].setPadding(MODE_DEFAULT_PADDING, MODE_DEFAULT_PADDING,
                        MODE_DEFAULT_PADDING, MODE_DEFAULT_PADDING);
                if (visible) {
                    visibleCount++;
                }
            }

            // add for RGK new UI solution by anxiang.xiao 20160506
            if (mModeViewsAdditional[i] != null) {
                /*
                 * boolean visible =
                 * ModeChecker.getModePickerVisible(getContext(), getContext()
                 * .getCameraId(), i); // check vFB // if vFB support, FB not
                 * need show in the mode picker line if (MODE_FACE_BEAUTY == i
                 * && FeatureSwitcher.isVfbEnable()) { visible = false; }
                 */
                boolean visible;
                if (i == MODE_SLOWMOTION && getContext().getCameraId() != 0)
                    visible = false;
                else
                    visible = true;

                mModeViewsAdditional[i].setVisibility(visible ? View.VISIBLE : View.GONE);
                mModeViewsAdditional[i].setLayoutParams(mLayoutParams);
                mModeViewsAdditional[i].setPadding(MODE_DEFAULT_PADDING, MODE_DEFAULT_PADDING,
                        MODE_DEFAULT_PADDING, MODE_DEFAULT_PADDING);
                if (visible) {
                    visibleCount++;
                }
            }
            // add end
        }
        // set margin botton of the last mode icon as 0.
        for (int i = MODE_ICON_ORDER.length - 1; i >= 0; i--) {
            int index = MODE_ICON_ORDER[i];
            if (mModeViews[index] != null && mModeViews[index].getVisibility() == View.VISIBLE) {
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(0, 0, 0, 0);
                mModeViews[index].setLayoutParams(params);
                break;
            }
        }

        for (int i = MODE_ICON_ORDER.length - 1; i >= 0; i--) {
            int index = MODE_ICON_ORDER[i];
            if (mModeViewsAdditional[index] != null
                    && mModeViewsAdditional[index].getVisibility() == View.VISIBLE) {
                /*
                 * LinearLayout.LayoutParams params = new
                 * LinearLayout.LayoutParams(
                 * LinearLayout.LayoutParams.WRAP_CONTENT,
                 * LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0,
                 * 0, 0, 0);
                 * mModeViewsAdditional[index].setLayoutParams(params); break;
                 */
            }
        }

        if (visibleCount <= 1) { // to enable/disable background
            // mScrollView.setVisibility(View.GONE);
        } else {
            // mScrollView.setVisibility(View.VISIBLE);
        }
        // remove temply for do not recore what been clicked
        // highlightCurrentMode();
        nohighlightAllMode();
    }

    @Override
    public boolean onLongClick(View view) {
        Log.d(TAG, "onLongClick(" + view + ")");
        if (view.getContentDescription() != null) {
            if (mModeToast == null) {
                mModeToast = OnScreenToast.makeText(getContext(), view.getContentDescription());
            } else {
                mModeToast.setText(view.getContentDescription());
            }
            mModeToast.showToast();
        }
        // don't consume long click event
        return false;
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        if (mScrollView != null) {
            mScrollView.setEnabled(enabled);
        }
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViews[i] != null) {
                mModeViews[i].setEnabled(enabled);
                mModeViews[i].setClickable(enabled);
            }
        }
        for (int i = 0; i < MODE_NUM_ALL; i++) {
            if (mModeViewsAdditional[i] != null) {
                mModeViewsAdditional[i].setEnabled(enabled);
                mModeViewsAdditional[i].setClickable(enabled);
            }
        }
    }

    @Override
    protected void onRelease() {
        super.onRelease();
        mModeToast = null;
    }

    private int getModeWidth() {
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),
                MODE_ICONS_NORMAL[MODE_PHOTO]);
        int bitmapWidth = bitmap.getWidth();
        return bitmapWidth + MODE_DEFAULT_PADDING * 2;

    }

    private int getDefaultMarginBottom() {
        // default show three and half mode icons
        return (mDisplayWidth - MODE_MIN_COUNTS * mModeWidth) / (MODE_MIN_COUNTS - 1)
                + (mModeWidth / (2 * (MODE_MIN_COUNTS - 1)));
    }

    public void setModePreference(ListPreference pref) {
        mModePreference = pref;
    }

    public boolean onTouch(View v, MotionEvent event) {

        final int action = event.getAction();

        Log.i(TAG, "ModePicker ontouch");
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                Log.e(TAG, "ModePicker event : down");
                break;

            case MotionEvent.ACTION_MOVE:
                Log.e(TAG, "ModePicker event : move");

                break;

            case MotionEvent.ACTION_UP:
                Log.e(TAG, "ModePicker event : up");

                break;
            case MotionEvent.ACTION_CANCEL:

                break;
        }

        return false;
    }
}
